package com.cmbyc.todolist.utils;

import org.apache.commons.lang3.time.DateUtils;

import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    /**
     * 清除日期的时分秒
     * @param date
     * @return
     */
    public static Date clearTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 在当前日期添加一天
     * @param date
     * @return
     */
    public static Date addOneDay(Date date) {
        date = clearTime(date);
        return DateUtils.addDays(date, 1);
    }

    public static Date addTowHour(Date date) {
//        date = clearTime(date);
        return DateUtils.addHours(date, -2);
    }
}
